package Pacote2;

import grails.test.*
import les.*
import grails.converters.*
import com.solution51.sfu.*;

class UploadTests extends functionaltestplugin.FunctionalTestCase {
	
	void testApareceFormParaArquivoParaJotasECoordenador() {
		
		get ("/usuario/login")
		
		form() {
			email = "jota@gmail.com"
			senha = "123456"
			click "entrar"
		}

		get ("/equipe/list")
				
		click "Bandinha 2011"
		
		assertContentContains '<input type="file" id="relatorio" name="relatorio"/>'
		
		click "Editar"
		
		assertContentContains '<input type="file" id="relatorio" name="relatorio"/>'
		
		click "Deslogar"
		
		get ("/usuario/login")
		
		form() {
			email = "bandinha@gmail.com"
			senha = "123456"
			click "entrar"
		}

		click "Bandinha 2011 (EJC2010)"
		
		assertContentContains '<input type="file" id="relatorio" name="relatorio"/>'
	}

	void testEnviarRelatorio() {
		FileWriter writer = new FileWriter(new File("novoArquivo.txt"));
		PrintWriter saida = new PrintWriter(writer);
		saida.println("Testando");
		saida.close();
		writer.close();
		
		
		get ("/usuario/login")
		
		form() {
			email = "jota@gmail.com"
			senha = "123456"
			click "entrar"
		}

		get ("/equipe/list")
				
		click "Bandinha 2011"
		
		click "Editar"
		
		form() {
			relatorio.contentType = "text/plain"
			relatorio.data = new File("novoArquivo.txt").bytes
			relatorio.valueAttribute = new File("novoArquivo.txt").absolutePath
			click "Atualizar"
		}
		
		assertContentContains "novoArquivo.txt"
	}

	void testRemoverRelatorio() {
		FileWriter writer = new FileWriter(new File("novoArquivo.txt"));
		PrintWriter saida = new PrintWriter(writer);
		saida.println("Testando");
		saida.close();
		writer.close();
		
		get ("/usuario/login")
		
		form() {
			email = "jota@gmail.com"
			senha = "123456"
			click "entrar"
		}

		get ("/equipe/list")
				
		click "Bandinha 2011"
		
		form() {
			click "Remover"
		}
		
		assertContentContains '<input type="file" id="relatorio" name="relatorio"/>'
				
	}
				
}
